package top.malaoshi.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.malaoshi.filter.TestFilter;
import top.malaoshi.filter.TestFilter2;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean registFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new TestFilter());
        //设置过滤器名称，可省略
        //registration.setName("TestFilter");
        //设置init参数
        //filterRegistrationBean.addInitParameter("name","lilei");
        //配置过滤规则
        registration.addUrlPatterns("/*");
        //执行顺序，只有1个过滤器时，可省略。越小越先执行
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean registFilter2() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new TestFilter2());
        //设置过滤器名称，可省略
        //registration.setName("TestFilter");
        //设置init参数
        //filterRegistrationBean.addInitParameter("name","lilei");
        //配置过滤规则
        registration.addUrlPatterns("/*");
        //执行顺序，只有1个过滤器时，可省略。越小越先执行
        registration.setOrder(2);
        return registration;
    }
}